<?php

namespace App\Models;

// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Tymon\JWTAuth\Contracts\JWTSubject;

class User extends Authenticatable implements JWTSubject
{
    use HasFactory, Notifiable;

    public $table = "users";
    public $prefix = "u_";
    public $primaryKey = "u_id";
    public $fillable = [
        'u_name', 'u_avatar', 'u_role', 'u_password', 'u_password_text',
        'u_level', 'u_ip', 'openid'
    ];

    protected $hidden = [
        'u_password',
        'remember_token',
    ];

    protected function casts(): array
    {
        return [
            'email_verified_at' => 'datetime',
            'password' => 'hashed',
        ];
    }

    public function getJWTIdentifier()
    {
        return $this->getKey();
    }

    public function getJWTCustomClaims()
    {
        return [];
    }

    public function getAuthPassword()
    {
        return $this->u_password;
    }

    public function adminRegister($userDataArr)
    {
        $userItem = $this->create($userDataArr);
        return $userItem->{$this->primaryKey};
    }
}
